home *** CD-ROM | disk | FTP | other *** search
/ Cre@te Online 2000 December / Cre@teOnline CD05.iso / MacSoft / XML ConsoleMax.sea / XML ConsoleMax / Required / esc.jar / com / extensibility / xml / SchemaFlavorPeekHandler.class (.txt) < prev    next >
Encoding:
Java Class File  |  2000-06-30  |  3.5 KB  |  129 lines

  1. package com.extensibility.xml;
  2.  
  3. import java.io.StringReader;
  4. import org.xml.sax.AttributeList;
  5. import org.xml.sax.HandlerBase;
  6. import org.xml.sax.InputSource;
  7.  
  8. class SchemaFlavorPeekHandler extends HandlerBase {
  9.    private String rootName;
  10.    private String rootPrefix;
  11.    private String rootNS;
  12.    private String firstChildName;
  13.    private int elementCount = 0;
  14.    private boolean isRoot;
  15.    private String flavor;
  16.    private URI uri;
  17.    private boolean maybeXSDL;
  18.  
  19.    public SchemaFlavorPeekHandler(URI var1) {
  20.       this.uri = var1;
  21.    }
  22.  
  23.    public void startDocument() {
  24.       this.isRoot = true;
  25.       this.flavor = null;
  26.    }
  27.  
  28.    public void startElement(String var1, AttributeList var2) {
  29.       ++this.elementCount;
  30.       if (this.isRoot) {
  31.          boolean var3 = false;
  32.          this.rootName = var1;
  33.          if (this.rootName.indexOf(":") > 0) {
  34.             this.rootPrefix = this.rootName.substring(0, this.rootName.indexOf(":") - 1);
  35.             this.rootName = this.rootName.substring(this.rootName.indexOf(":") + 1);
  36.          }
  37.  
  38.          for(int var4 = 0; var4 < var2.getLength(); ++var4) {
  39.             String var5 = var2.getName(var4);
  40.             if (this.rootPrefix != null && var5.equals(String.valueOf("xmlns:").concat(String.valueOf(this.rootPrefix)))) {
  41.                this.rootNS = var2.getValue(var4);
  42.             } else if (var5.equals("xmlns")) {
  43.                this.rootNS = var2.getValue(var4);
  44.             } else if (var5.equals("name")) {
  45.                var3 = true;
  46.             }
  47.          }
  48.  
  49.          this.isRoot = false;
  50.          if (this.rootName.equals("DCD")) {
  51.             this.flavor = DCDFlavor.NAME;
  52.          } else if (this.rootName.equals("DocumentDef")) {
  53.             this.flavor = DDMLFlavor.NAME;
  54.          } else if (this.rootName.equals("schema")) {
  55.             if (this.rootNS != null && this.rootNS.indexOf("w3.org") >= 0) {
  56.                if (this.rootNS.indexOf("1999/05/06") >= 0) {
  57.                   if (var3) {
  58.                      this.flavor = "xsd.1999.05.06";
  59.                   } else {
  60.                      this.flavor = "xsd.1999.12.17";
  61.                   }
  62.                } else if (this.rootNS.indexOf("WD-xmlschema-1-19991217") > 0) {
  63.                   this.flavor = "xsd.1999.12.17";
  64.                } else if (this.rootNS.indexOf("WD-xmlschema-1-20000225") > 0) {
  65.                   this.flavor = "xsd";
  66.                } else if (this.rootNS.equals("http://www.w3.org/1999/XMLSchema")) {
  67.                   this.maybeXSDL = true;
  68.                } else {
  69.                   this.flavor = "xsd";
  70.                }
  71.             } else {
  72.                this.flavor = SOX2Flavor.NAME;
  73.             }
  74.          } else if (this.rootName.equals("Schema")) {
  75.             String var6 = this.uri.getShortName().substring(this.uri.getShortName().lastIndexOf(46) + 1);
  76.             if (this.rootNS != null && this.rootNS.indexOf("schemas-microsoft-com") >= 0) {
  77.                if (var6.equals(BIZFlavor.NAME)) {
  78.                   this.flavor = BIZFlavor.NAME;
  79.                } else {
  80.                   this.flavor = XDRFlavor.NAME;
  81.                }
  82.             }
  83.          } else if (this.rootName.equals("module")) {
  84.             this.flavor = DDMLFlavor.NAME;
  85.          }
  86.       } else if (this.maybeXSDL) {
  87.          if (!var1.equals("type") && !var1.equals("datatype")) {
  88.             if (var1.equals("simpleType") || var1.equals("complexType")) {
  89.                this.flavor = "xsd";
  90.             }
  91.          } else {
  92.             this.flavor = "xsd.1999.12.17";
  93.          }
  94.       }
  95.  
  96.       if (this.flavor != null) {
  97.          throw new RuntimeException();
  98.       }
  99.    }
  100.  
  101.    String getRootName() {
  102.       return this.rootName;
  103.    }
  104.  
  105.    String getRootNS() {
  106.       return this.rootNS;
  107.    }
  108.  
  109.    int getElementCount() {
  110.       return this.elementCount;
  111.    }
  112.  
  113.    public String getFlavor() {
  114.       if (this.flavor != null) {
  115.          return this.flavor;
  116.       } else if (this.rootName == null) {
  117.          return DTDFlavor.NAME;
  118.       } else if (this.maybeXSDL) {
  119.          return "xsd";
  120.       } else {
  121.          return this.getElementCount() > 0 ? null : DTDFlavor.NAME;
  122.       }
  123.    }
  124.  
  125.    public InputSource resolveEntity(String var1, String var2) {
  126.       return !var2.startsWith("urn") && var2.indexOf("/urn:") == -1 ? null : new InputSource(new StringReader(""));
  127.    }
  128. }
  129.